
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%
chatManagers.DBMSManager dbm = new chatManagers.DBMSManager();

int cid = 0;
String chatID = "";
String uName = request.getRemoteUser();

chatID = request.getParameter("chatid");
if(chatID!=null && !chatID.equals("")) {
    cid = new Integer(chatID).intValue();
}

try{
    if(dbm.isChatActive(cid) && dbm.checkLogin(uName)!=0) {
//We're cool
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Chat Rooms</title>
        <link href="../includes/chat_mobile.css" rel="stylesheet" type="text/css" media="screen" />
        <link href="../includes/default.css" rel="stylesheet" type="text/css" screen="media" />
        
        <script type="text/javascript" src="../includes/xui-0.9.1.js"></script>
        <script type="text/javascript" src="../includes/common_mobile.js"></script>
        
        <jsp:useBean id="ub" class="chatManagers.UserBean" scope="session" />
        <jsp:setProperty name="ub" property="chatid" />
        <jsp:setProperty name="ub" property="chatName" />
    </head>
    
    <body onload="signOn(<jsp:getProperty name="ub" property="chatid" />,<jsp:getProperty name="ub" property="userid" />);" onUnload = "signOff();">
        
        <div id="chatheader">
            <div id="header-left-col">
			<h1>
			<!--PAGEHEADING-->
			</h1>
                <div class="h3"><jsp:getProperty name="ub" property="chatName" /></div>
            </div>
            <div id="header-right-col">
                <form action="#" id="soff" style="margin-bottom: 0px;">
                    <a href="javascript:signOff()">Exit Chat</a><br/>
                    <a id="endchat" style="display:none;" href="javascript: endChat();" />End Chat</a>
                </form>
            </div>
        </div>
        
        <div id="chatbody">
            <div id="body-left-col">
                <div id="tabBar">
                    <div id="chatTab" class="selectedTab" onclick="toggleWindow(this);">Chat</div>
                    <div id="membersTab" class="hiddenTab" onclick="toggleWindow(this);">Members</div>
                </div>
                
                <form action="#" id="membersblock">
                    <div id="members" class="side-block"></div>
                </form>
                
                <div id="chat_contents"></div>               
                <form action="#" id="commentfrm">
                    <input type="hidden" name="chatid" id="chatid" value='<jsp:getProperty name="ub" property="chatid" />' />
                    <input type="hidden" name="userid" id="userid" value='<jsp:getProperty name="ub" property="userid" />' />
                    <input type="hidden" name="doAction" id="doAction" value="signon" />
                    <input type="hidden" name="lastmsgid" id="lastmsgid" value="" />
                    <input type="hidden" name="startmsgid" id="startmsgid" value="" />
                    <textarea id="comment" name="comment" onfocus="window.scrollTop=window.scrollHeight;" onkeypress="return event.keyCode!=13"></textarea><input id="sendbutton" type="button" value="Send" onclick="addComment();"/>
                </form>
                
            </div>
        </div>
    </body>
</html>
<%
    } else {
        response.sendRedirect("index.jsp");
    }
    
} catch (Exception e) {
    e.printStackTrace();
} finally {
    dbm.closeConnection();
}

%>
